<template>
	<scroll ref="mescrollRef" @init="mescrollInit" :down="downOption"  @down="downCallback" :up="upOption" @up="upCallback" @emptyclick="emptyClick">
		<stop isBack>
			<view slot="content">保养计划</view>
		</stop>
		<view class="bcf padlr3 padtb2 bdtso">
			<search class="fs8 tac" placeholder=" 单号 \ 物资名称 \ 编码 \ 型号"  v-model="search" @search="doSearch()"></search>
		</view>
		<view class="padlr3">
			<view class="bcf pos-r mart3 pad2 round2 shadow"   @tap="mySlide(index)"
			v-for="plan,index in data" :key="plan.id">
				<view class="pos-r padr2 ofh">
					<check-plan :item="plan"></check-plan>
					<ripple></ripple>
					<sslide ref="mySlideBox">
						<view class="bg-orange flex-c flex-fill pad2 round3">
							<view class="flex1 flcc pad5 pos-r bdbda" @tap="goto('/pages/machi_maintain/maintain_plan_info?id=' + plan.id)">
								查看
								<ripple></ripple>
							</view>
							<view class="flex1 flcc pad3 pos-r bdbda" @tap="arrange(plan.id)">
								排期
								<ripple></ripple>
							</view>
							<view class="flex1 flcc pad5 pos-r" @tap="stopIt(plan.id)" v-if="plan.isRun">
								停止计划
								<ripple></ripple>
							</view>
							<view class="flex1 flcc pad5 pos-r" @tap="startIt(plan.id)" v-if="!plan.isRun">
								启动计划
								<ripple></ripple>
							</view>
						</view>
					</sslide>
				</view>
			</view>
		</view>
		<loading :loading="myIsLoading"></loading>
	</scroll>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import List from '../../assets/js/list.js'
	
	import checkPlan from '../../templete/machine/machine_plan_maintain_item.vue'
	
	export default {
		mixins:[MescrollMixin],
		components:{checkPlan},
		data() {
			let list = new List()
			return {
				list,
				where:{
					eq:{
						status:'',
						emergency:'',
						level:'',
					}
				},
				search:"",
				data:[]
			}
		},
		methods: {
			reload(){
				this.showLoading()
				this.data=[]
				this.list.setData({_order:{id:"DESC"},_where:this.where,_search:this.search}).reload()
			},
			doSearch(){
				this.showLoading()
				this.data=[]
				this.list.setData({_order:{id:"DESC"},_where:this.where,_search:this.search}).reload()
			},
			arrange(id){
				this.$api.get('/api/arrange/machinePlanMaintains/'+id,{},res=>{
					this.showLoading()
					this.reload()
				})
			},
			stopIt(id){
				this.$api.patch('/api/machinePlanMaintains/'+id,{isRun:false},res=>{
					this.log(res)
					this.reload()
				})
			},
			startIt(id){
				this.$api.patch('/api/machinePlanMaintains/'+id,{isRun:true},res=>{
					this.log(res)
					this.reload()
				})
			}
		},
		mounted() {
			this.list.initMescroll(this).setUrl('/api/machinePlanMaintains').setData({
				_order:{id:"DESC"},
				_where:this.where,
				_search:this.search,
			}).setCbFunc(res=>{
				this.data = res
				this.clearLoading()
			}).reload()
		},
		onShow() {
			this.log("onshow")
			this.showLoading()
			this.list.reload()
		},
		watch:{
		}
	}
</script>

<style>

</style>
